package AOPdemo1;

import Service.AccountService;
import Service.impl.AccountServiceImpl;
import domain.Account;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import java.util.List;

/**
 * @author Rain
 * @Description :
 * @date 2022/08/22 16:57
 */
public class MyAspect implements MethodInterceptor {
//定义通知
    public void checkPermission(){
        System.out.println("开启权限检查,如果有权限就放行...");
    }

    public void commitTransaction(){
        System.out.println("模拟事务提交");
    }

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        checkPermission();
        if (invocation.getMethod().getName().startsWith("add")) {
            System.out.println("是add方法!");
        }

        Object proceed = invocation.proceed();
        commitTransaction();
        return null;
    }
}
